<template>
	<view class="dianpu">
		<view class="item">
			<view class="title">店铺名称:</view>
			<input v-model="Name" class="inputitem" placeholder="请输入店铺名称"></input>
		</view>
		<view class="item">
			<view class="title">电话:</view>
			<input v-model="Phone" class="inputitem" placeholder="请输入电话号码"></input>
		</view>
		<view class="item dizhi">
			<view class="title">位置:</view>
			<view class="inputitem">
				{{Location}}
				<image src="../../static/dangqianweizhi.png" v-on:click="onLocation"></image>
			</view>
			
		</view>
		<view class="item dizhi">
			<view class="title">选择地址:</view>
			<input v-model="Address" class="inputitem" placeholder="请输入地址"></input>
		</view>
		
		<view class="edit" v-on:click="onEdit">立即修改</view>
	</view>
</template>

<script>
	import http from "../../common/http.js"
	export default {
		data() {
			return {
				Name:"",
				Phone:"",
				Location:"",
				Location2:"",
				Address:"",
				storeid:0
			}
		},
		onLoad(options) {
			this.storeid = options.storeid
			this.requestStoreInfo()
		},
		onShow() {
			var center = uni.getStorageSync("center")
			if (center != void 0) {
				this.Location = center
				uni.removeStorage({
					key:"center"
				})
			}
		},
		methods: {
			requestStoreInfo() {
				var self = this
				http.get("/store/storeinfo", {"storeid":this.storeid}, (r)=>{
					console.log(r)
					self.Name = r.Name
					self.Phone = r.Phone
					self.Location = r.Location
					self.Address = r.Address
				})
			},
			onEdit() {
				http.post("/store/storeinfo", {
					"storeid":this.storeid,
					"name":this.Name, 
					"location":this.Location, 
					"phone":this.Phone, 
					"addr":this.Address,
				}, (r)=>{
					console.log(r)
					uni.showToast({
						title:"修改成功",
						icon:'none',
						success() {
							setTimeout(()=>{uni.navigateBack()}, 1000)
						}
					})
				})
			},
			onLocation() {
				uni.navigateTo({
					url:"../map/map?center="+this.Location
				})
				
				return
				var self = this
				uni.showLoading({
					title:"正在定位.."
				})
				
				uni.getLocation({
					type:"wgs84",
					success(res) {
						uni.hideLoading()
						console.log(res)
						self.Location = res.longitude+","+res.latitude
						self.Location2 = res.latitude+","+res.longitude
						
						// self.getLocDescripe()
					},
					fail(err) {
						uni.hideLoading()
					
					}
				})
			},
			getLocDescripe(){
				var self = this
				var url = "https://apis.map.qq.com/ws/geocoder/v1/"
				http.get(url, {
					"key":"KMSBZ-QFN33-MHB34-3VVHK-TLOGE-4NFUY", 
					"location":this.Location2,
				},(r)=>{
					
				})
			}
		}
	}
</script>

<style>
	.item {
		padding: 10px 15px;
	}
	.item .title { 
		font-size: 15px;
		height: 30px;
	}
	.inputitem {
		background-color: #f3f3f2;
		height: 44px;
		padding: 0 10px;
		border-radius: 10px;
		line-height: 44px;
		color: #333333;
	}
	.edit {
		margin-top: 20px;
		background-color: #75D7E0;
		color: white;
		width: 80%;
		margin-left: 10%;
		text-align: center;
		height: 50px;
		border-radius: 25px;
		line-height: 50px;
		font-size: 18px;
	}
	.dizhi .content {
		/* padding-right: 50px; */
		/* box-sizing: border-box; */
	}
	.dizhi image {
		width: 40px;
		height: 40px;
		float: right;
	}
</style>
